#include <stdio.h>
#include <assert.h>
#include <math.h>
#define N 10000

double f1(double x,double a,double b)
{
	assert(x >= a && x <= b);
	return 1/x;
}

double f2(double x,double a,double b)
{
	assert(x >= a && x <= b);
	return 4/(1+x*x);
}

double Gauss(double a,double b,int n,double (*f)(double ,double ,double ))
{
	double h = 0.0001;
	double t = h/2/pow(3,1/2);
	double x[N+1];
	double g = 0;
	int i;
	for(i = 0;i < n+1;i++)
		x[i] = a + i*h;
	for(i = 0;i < n;i++)
		g += f(((x[i]+x[i+1])/2-t),a,b);
	for(i = 0;i < n;i++)
		g += f(((x[i]+x[i+1])/2+t),a,b);
	g = g*h/2.0;
	return g;
}

int main()
{
	double s;
	double t;
	s = Gauss(1,2,N,f1);
	t = log(2.0);
	printf("Gauss ln2：%.16f\n",s);
	printf("Math ln2：%.16f\n",t);
	s = Gauss(0,1,N,f2);
	t = 3.141593;
	printf("Gauss PI：%.16f\n",s);
	printf("Math PI：%.16f\n",t);
	return 0;
}
